﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.Extensions.Options;
using NiuX.Domain.Entities;
using NiuX.Domain.Exceptions;
using NiuX.Domain.Repositories;
using NiuX.Domain.Specifications;
using NiuX.Domain.Specifications.Exceptions;
using NiuX.Specifications;

namespace NiuX.EntityFrameworks
{
    public partial class EfCoreRepository<TDbContext, TEntity>
    {
        public virtual async Task<TEntity> InsertNowAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default)
        {
            return await InsertAsync(entity, true, cancellationToken);
        }

        public virtual async Task InsertManyNowAsync([NotNull] IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)
        {
            await InsertManyAsync(entities, true, cancellationToken);
        }

        public virtual async Task DeleteNowAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default)
        {
            await DeleteAsync(entity, true, cancellationToken);
        }

        public virtual async Task DeleteNowAsync([NotNull] Expression<Func<TEntity, bool>> predicate, CancellationToken cancellationToken = default)
        {
            await DeleteAsync(predicate, true, cancellationToken);
        }

        public virtual async Task DeleteManyNowAsync([NotNull] IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)
        {
            await DeleteManyAsync(entities, true, cancellationToken);
        }

        public virtual async Task<TEntity> UpdateNowAsync([NotNull] TEntity entity, CancellationToken cancellationToken = default)
        {
            return await UpdateAsync(entity, true, cancellationToken);
        }

        public virtual async Task UpdateManyNowAsync([NotNull] IEnumerable<TEntity> entities, CancellationToken cancellationToken = default)
        {
            await UpdateManyAsync(entities, true, cancellationToken);
        }
    }

    public partial class EfCoreRepository<TDbContext, TEntity, TKey>
    {
        public virtual async Task DeleteNowAsync(TKey id, CancellationToken cancellationToken = default)
        {
            await DeleteAsync(id, true, cancellationToken);
        }

        public virtual async Task DeleteManyNowAsync([NotNull] IEnumerable<TKey> ids, CancellationToken cancellationToken = default)
        {
            await DeleteManyAsync(ids, true, cancellationToken);
        }
    }


}
